{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "美瑞分别是20手、20手和10手，现在盈亏的平衡点是什么价位"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.00938"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "平衡点 =(20*1.01068+20*1.00899+10*1.00756)/50\n",
    "平衡点"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "现在盈亏的平衡点是1.00938"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 127,
   "metadata": {},
   "outputs": [],
   "source": [
    "目标位置=0.99587\n",
    "当前净值=1885478"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "问1：如果顺利下跌，不再增加仓位，中间也不减仓，共持仓：50标准手，当前净值是：1885478美元，问：当价格是多少的时候，可以翻一倍？\n",
    "注：1标准手，波动1个点（小数点后第4位），10美金。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.25519"
      ]
     },
     "execution_count": 105,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sympy import *\n",
    "round(solve(50*(1.00938-x)*100000-1885478*2,x)[0],5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "当价格是0.25519的时候，可以翻一倍"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "问题2：到目标位置的时候，盈利比例是多少？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.013384453823138909"
      ]
     },
     "execution_count": 109,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "盈利比例=1-(目标位置/平衡点)\n",
    "盈利比例"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "盈利比例是1.3%"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "问3：假如想要到目标位置的时候，赚一倍，那么在中间，还需要增加多少手的仓位？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.002625"
      ]
     },
     "execution_count": 113,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "假设加仓位=平衡点-(平衡点-目标位置)/2\n",
    "假设加仓位"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "33775.0"
      ]
     },
     "execution_count": 117,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "浮盈=(平衡点-假设加仓位)*100000*50\n",
    "round(浮盈,0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 125,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2691.0"
      ]
     },
     "execution_count": 125,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#翻一倍还需要再赚（当前净值-浮盈）\n",
    "缺额=1885478-33775\n",
    "round(solve((x+50)*(假设加仓位-目标位置)*100000-缺额,x)[0],0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "需要增加2691手的仓位"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
